/**
 * @file    GuiDialogs.h
 * @brief   Collects some commonly used dialogs.
 *          
 *          
 *          
 ****************************************************************************
 * @version $Id: GuiDialogs.h 2457 2010-05-12 03:15:17Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Gui_GuiDialogs_H__
 #define __WOSH_Gui_GuiDialogs_H__


 #include <QtGui/QDialog>
 #include <QAbstractTableModel>


 #include <framework/gui/dialogs/DialogCreateGui.h>
 #include <framework/gui/dialogs/DialogLoadBundle.h>
 #include <framework/gui/dialogs/DialogLogin.h>

 #include <framework/gui/widgets/wCore_URI.h>
 #include <framework/gui/widgets/wCore_PropertiesProvider.h>

 #include <QtGui/QButtonGroup>
 #include <QtGui/QHeaderView>
 #include <QtGui/QDialogButtonBox>
 #include <QtGui/QVBoxLayout>


namespace Ui {
 class DialogGuiMapping; // DialogGuiMapping.ui
};
namespace wosh {
 namespace gui {


class GuiMappingTableModel : public QAbstractTableModel
 {
	Q_OBJECT

	public:
		GuiMappingTableModel(QObject *parent = 0) : QAbstractTableModel(parent) { }
		using QAbstractTableModel::reset;

		int rowCount(const QModelIndex &parent = QModelIndex()) const;

		int columnCount(const QModelIndex &parent = QModelIndex()) const { (void)parent; return 3; }

		QVariant data(const QModelIndex &index, int role) const;

		QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

	public: // editable
		 Qt::ItemFlags flags(const QModelIndex &index) const {
			return QAbstractItemModel::flags(index) | Qt::ItemIsEnabled;// | Qt::ItemIsEditable;
		  }

}; // class def

class DialogGuiMapping : public QDialog
 {
	Q_OBJECT

	public:
		DialogGuiMapping( QWidget *parent = NULL );
		virtual ~DialogGuiMapping();

	public slots:
		void refreshData();

	protected:
		void changeEvent(QEvent *e);

	private:
		Ui::DialogGuiMapping *m_ui;
		GuiMappingTableModel* tableModel;

}; // class def















class DialogSerializableEditor : public QDialog
 {
	Q_OBJECT

	public:
		DialogSerializableEditor( QWidget *parent = NULL );

	public:
		WRESULT loadObject( ISerializable* object );
		WRESULT saveObject( ISerializable* object );

	protected:
		void changeEvent(QEvent *e);

	protected:
		IWidgetSerializable* obj_gui;

	protected:
		QVBoxLayout* vLayout;
		QDialogButtonBox *buttonBox;

}; // class def


































class DialogUriSelector :  public QDialog  {

	Q_OBJECT

	public:

		DialogUriSelector(QWidget *parent = 0) : QDialog(parent)
		 {
			this->wUriSelector = new wCore_URI(this);
			this->wUriSelector->setObjectName(QString::fromUtf8("wCore_URI"));

			this->buttonBox = new QDialogButtonBox(this);
			this->buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
			this->buttonBox->setOrientation(Qt::Horizontal);
			this->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

			this->verticalLayout = new QVBoxLayout(this);
			this->verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
			this->verticalLayout->addWidget(wUriSelector);
			this->verticalLayout->addWidget(buttonBox);

			this->resize(300, 100);

			QObject::connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
			QObject::connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
		 }

		virtual ~DialogUriSelector() { }

	public:

		const URI& getTargetURI() const			{ return this->wUriSelector->getTargetURI(); }
		URI& getTargetURI()						{ return this->wUriSelector->getTargetURI(); }


	protected:

		QVBoxLayout *verticalLayout;
		wCore_URI *wUriSelector;
		QDialogButtonBox *buttonBox;


}; // class def






class DialogUserSelector :  public QDialog  {

	Q_OBJECT

	public:

		DialogUserSelector(QWidget *parent = 0) : QDialog(parent)
		 {
			this->txtUser = new QLineEdit(this);
			this->txtUser->setObjectName(QString::fromUtf8("DialogUserSelector"));

			this->buttonBox = new QDialogButtonBox(this);
			this->buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
			this->buttonBox->setOrientation(Qt::Horizontal);
			this->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);

			this->verticalLayout = new QVBoxLayout(this);
			this->verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
			this->verticalLayout->addWidget(txtUser);
			this->verticalLayout->addWidget(buttonBox);

			this->resize(300, 100);

			QObject::connect(this->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
			QObject::connect(this->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
		 }

		virtual ~DialogUserSelector() { }

	public:

		std::string getUser() const {
			return std::string( this->txtUser->text().toLatin1().data() );
		 }

	protected:

		QVBoxLayout *verticalLayout;
		QLineEdit* txtUser;
		QDialogButtonBox *buttonBox;


}; // class def








class WidgetPropertiesEditor :  public QWidget  {

	Q_OBJECT

	public:

		WidgetPropertiesEditor(QWidget *parent = 0) : QWidget(parent)
		 {
			this->wUriSelector = new wCore_URI(this);
			this->wUriSelector->setObjectName(QString::fromUtf8("wCore_URI"));

			this->wProperties = new wCore_PropertiesProvider(this);
			this->wProperties->setObjectName(QString::fromUtf8("wCore_PropertiesProvider"));

			this->verticalLayout = new QVBoxLayout(this);
			this->verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
			this->verticalLayout->setSpacing(2);
			this->verticalLayout->setMargin(3);
			this->verticalLayout->addWidget(this->wUriSelector);
			this->verticalLayout->addWidget(this->wProperties);

			this->setObjectName(QString::fromUtf8("WidgetPropertiesEditor"));
			QIcon icon;
		    icon.addPixmap(QPixmap(QString::fromUtf8(":/icons/var/extras/icons/menu.tools.propertieseditor.png")), QIcon::Normal, QIcon::Off);
	        this->setWindowIcon(icon);
			this->setWindowTitle( tr("Properties Editor") );
			this->resize(300, 200);

			QObject::connect(this->wUriSelector, SIGNAL(changedURI(const URI&)), this, SLOT(changedURI(const URI&)));

			this->wProperties->init();
		 }

		virtual ~WidgetPropertiesEditor() { }

	public:

		void closeEvent(QCloseEvent*) {
			this->deleteLater();
		 }

	protected slots:

		void changedURI( const URI& uri )
		 {
			if ( this->wProperties->getTargetURI() == uri )
				return; // dont flood, there is a Refresh button!
			this->wProperties->setTargetURI(uri);
			if ( !uri.isValid() )
				this->setWindowTitle( tr("Properties Editor") );
			else {
				this->setWindowTitle( tr("Properties of %1").arg(uri.toString().c_str()) );
				this->wProperties->refreshAll();
			}
		 }

	protected:

		QVBoxLayout *verticalLayout;
		wCore_URI *wUriSelector;
		wCore_PropertiesProvider *wProperties;


}; // class def





























 }; // namespace gui
}; // namespace wosh


#endif //__WOSH_Gui_GuiDialogs_H__
